package view;

import java.awt.EventQueue;
import java.awt.Frame;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Toolkit;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class Main extends JFrame {

	private JPanel contentPane;
	private JMenuItem mntmQuitter;
	private JMenuItem mntmAPropos;
	private JPanel toppanel;
	private JTable table;
	private JToolBar toolBar;
	private JButton btncontact;
	private Color topcolor = new Color(119, 159, 223);
	private JTextField tbSearch;
	private JButton btsearch;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Main() {
		this.setExtendedState(Frame.MAXIMIZED_BOTH);
		InitComponents();
		CreateEvents();
	}
	
	private void InitComponents(){
		setTitle("Mes Contacts");
		setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/ressources/1342881392_people.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 722, 551);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFichier = new JMenu("Fichier");
		menuBar.add(mnFichier);
		
		mntmQuitter = new JMenuItem("Quitter");
		
		mnFichier.add(mntmQuitter);
		mntmQuitter.setIcon(new ImageIcon(Main.class.getResource("/ressources/1342873044_button_cancel.png")));
		
		JMenu mnAide = new JMenu("Aide");
		menuBar.add(mnAide);
		
		mntmAPropos = new JMenuItem("A Propos");
		
		mntmAPropos.setIcon(new ImageIcon(Main.class.getResource("/ressources/1342884780_Information.png")));
		mnAide.add(mntmAPropos);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(178,205,248));
		contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
		setContentPane(contentPane);
		
		toppanel = new JPanel();
		toppanel.setBorder(null);
		toppanel.setBackground(topcolor);
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addComponent(toppanel, GroupLayout.DEFAULT_SIZE, 706, Short.MAX_VALUE)
				.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 706, Short.MAX_VALUE)
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addComponent(toppanel, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 620, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		
		table = new JTable();
		table.setBackground(new Color(51, 204, 204));
		scrollPane.setViewportView(table);
		
		toolBar = new JToolBar();
		toolBar.setBackground(topcolor);
		toolBar.setFloatable(false);
		
		tbSearch = new JTextField();
		tbSearch.setColumns(10);
		
		btsearch = new JButton("");
		btsearch.setBackground(topcolor);
		btsearch.setForeground(topcolor);
		btsearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btsearch.setIcon(new ImageIcon(Main.class.getResource("/ressources/1342889682_system-search.png")));
		GroupLayout gl_toppanel = new GroupLayout(toppanel);
		gl_toppanel.setHorizontalGroup(
			gl_toppanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_toppanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(toolBar, GroupLayout.PREFERRED_SIZE, 153, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(tbSearch, GroupLayout.PREFERRED_SIZE, 191, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btsearch, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(307, Short.MAX_VALUE))
		);
		gl_toppanel.setVerticalGroup(
			gl_toppanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_toppanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_toppanel.createParallelGroup(Alignment.LEADING)
						.addComponent(toolBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_toppanel.createParallelGroup(Alignment.TRAILING)
							.addComponent(btsearch)
							.addComponent(tbSearch, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		
		btncontact = new JButton("New Contact");
		btncontact.setBackground(topcolor);
		btncontact.setIcon(new ImageIcon(Main.class.getResource("/ressources/1342888119_contact-new.png")));
		btncontact.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		toolBar.add(btncontact);
		toppanel.setLayout(gl_toppanel);
		contentPane.setLayout(gl_contentPane);
	}
	private void CreateEvents(){
		mntmQuitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});	
		mntmAPropos.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JOptionPane.showConfirmDialog(null, "Premier appli java Standard Edition de OWONA\n\n@Twitter","A Propos",JOptionPane.DEFAULT_OPTION );
				}
			
			
		});
	}
}
